package ae.pcfc.etks.online.common.domain;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

/**
 * ServiceRole entity. @author Mohtisham.Salahria
 */
@Entity
@Table(name = "T_ETKS_SERVICE_ROLE", schema = "ETKS_ONLINE_DBA")
@SequenceGenerator(name = "SQ_ETKS_S_ROLE", sequenceName = "SQ_ETKS_S_ROLE", initialValue = 1, allocationSize = 1)
public class ServiceRole implements java.io.Serializable {

	// Fields

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private Long srId;
	private Service Service;
	private Long roleId;
	private String srSecurityRoleName;
	private Set<ClientServiceRole> ClientServiceRoles = new HashSet<ClientServiceRole>(
			0);
	private Set<ClientServiceRoleReq> ClientServiceRoleReqs = new HashSet<ClientServiceRoleReq>(
			0);
	private Set<UserServiceSecurity> UserServiceSecurities = new HashSet<UserServiceSecurity>(
			0);

	// Constructors

	/** default constructor */
	public ServiceRole() {
	}

	/** minimal constructor */
	public ServiceRole(Long roleId) {
		this.roleId = roleId;
	}

	/** full constructor */
	public ServiceRole(Service Service,
			Long roleId, Set<ClientServiceRole> ClientServiceRoles) {
		this.Service = Service;
		this.roleId = roleId;
		this.ClientServiceRoles = ClientServiceRoles;
	}

	// Property accessors
	@Id
	@GeneratedValue( strategy = GenerationType.SEQUENCE, generator="SQ_ETKS_S_ROLE")
	@Column(name = "SR_ID", nullable = false, precision = 11, scale = 0)
	public Long getSrId() {
		return this.srId;
	}

	public void setSrId(Long srId) {
		this.srId = srId;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "SERVICE_ID")
	public Service getService() {
		return this.Service;
	}

	public void setService(Service Service) {
		this.Service = Service;
	}

	@Column(name = "ROLE_ID", nullable = false, precision = 11, scale = 0)
	public Long getRoleId() {
		return this.roleId;
	}

	public void setRoleId(Long roleId) {
		this.roleId = roleId;
	}
	
	@Column(name = "SR_SECURITY_ROLE_NAME", length = 100)
	public String getSrSecurityRoleName() {
		return srSecurityRoleName;
	}

	public void setSrSecurityRoleName(String srSecurityRoleName) {
		this.srSecurityRoleName = srSecurityRoleName;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "serviceRole")
	public Set<ClientServiceRole> getClientServiceRoles() {
		return this.ClientServiceRoles;
	}

	public void setClientServiceRoles(
			Set<ClientServiceRole> ClientServiceRoles) {
		this.ClientServiceRoles = ClientServiceRoles;
	}
	
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "serviceRole")
	public Set<ClientServiceRoleReq> getClientSRoleReqs() {
		return this.ClientServiceRoleReqs;
	}

	public void setClientSRoleReqs(
			Set<ClientServiceRoleReq> ClientServiceRoleReqs) {
		this.ClientServiceRoleReqs = ClientServiceRoleReqs;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "serviceRole")
	public Set<UserServiceSecurity> getUserServiceSecurities() {
		return UserServiceSecurities;
	}

	public void setUserServiceSecurities(
			Set<UserServiceSecurity> userServiceSecurities) {
		UserServiceSecurities = userServiceSecurities;
	}
	
	@Override
	public boolean equals(Object obj) {
		// TODO Auto-generated method stub
		if(!(obj instanceof ServiceRole)){
			return false;
		}
		ServiceRole serviceRole = (ServiceRole)obj;
		if(this.getSrId().longValue() == serviceRole.getSrId().longValue()){
			return true;
		}
		return super.equals(obj);	
	}
}